package com.huawei.itemservice.controller;


import com.huawei.common.pojo.Result;
import com.huawei.itemservice.pojo.dto.ItemDTO;
import com.huawei.itemservice.pojo.dto.idDTO;
import com.huawei.itemservice.service.ItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;



@Tag(name = "商品模块")
@RestController
@RequestMapping("/items")
public class itemController {


    @Autowired
    private ItemService itemService;

    @Operation(summary = "测试-根据id查询商品")
    @GetMapping("/test/{id}")
    public Result getItem(@RequestHeader("Authorization") String token, @PathVariable("id") Long id){
        System.out.println("知行了item方法 " + id);
        return Result.success();
    }



    @Operation(summary = "创建商品信息")
    @PostMapping("/createItem")
    public Result createItem(@RequestHeader("Authorization") String token,@RequestBody ItemDTO item){
        System.out.println("知行了createItem方法 " + item);
        return itemService.createItem(item);
    }




    @Operation(summary = "上传菜品照片")
    @PostMapping("/uploadProfile")
    public Result uploadProfile(@RequestHeader("Authorization") String token, MultipartFile profile){
        return itemService.uploadProfile(profile);
    }




    @Operation(summary = "更新菜品信息")
    @PutMapping("/updateItem")
    public Result updateItem(@RequestHeader("Authorization") String token,@RequestBody ItemDTO itemdto){
        return itemService.updateItem(itemdto);
    }



    @Operation(summary = "删除菜品信息")
    @DeleteMapping("/{id}")
    public Result deleteItem(@RequestHeader("Authorization") String token,@PathVariable("id") Long id){
        return itemService.deleteItem(id);
    }






    @Operation(summary = "根据id查询菜品信息")
    @GetMapping("/{id}")
    public Result getItemById(@RequestHeader("Authorization") String token,@PathVariable("id") Long id){
        return itemService.getItemById(id);
    }





    @Operation(summary = "查询所有菜品id")
    @GetMapping("/findAllItems")
    public Result findAllItems(@RequestHeader("Authorization") String token){
        return itemService.findAllItems();
    }


    @Operation(summary = "根据id集合查询菜品信息")
    @PostMapping("/findByIds")
    public Result findByIds(@RequestHeader("Authorization") String token,@RequestBody idDTO iddto){
        System.out.println(iddto);
        return itemService.findByIds(iddto.getIds());
    }



    @Operation(summary = "查询所有菜品信息")
    @GetMapping("/getAllItems")
    public Result getAllItems(@RequestHeader("Authorization") String token){
        return itemService.getAllItems();
    }







}
